#!/usr/bin/env python


__author__= 'yingnn'

'''methylation fitting using random forest'''


import sys


if len(sys.argv) < 3:
	print sys.argv[0], "fname, n_trees, n_jobs\n"
	exit()

fname=sys.argv[1]
n_trees=int(sys.argv[2])
# n_trees=sys.argv[2]
jobs=int(sys.argv[3])

import pandas as pd
import numpy as np
# from sklearn.ensemble import (RandomForestClassifier, b)
from sklearn.ensemble import RandomForestClassifier as rfc

# dat= pd.read_csv(fname, header=None)

dat= pd.read_table(fname, header=None)

dat= dat.transpose()

dat1= dat.dropna(axis=1, how='any')

# dat1x= dat1.iloc[:,:-1].as_matrix()
# dat1y= dat1.iloc[:,-1].as_matrix()

# run_time=10

# for i in np.arange(run_time):
	

rfc1= rfc(n_estimators=n_trees, oob_score=True, n_jobs=jobs, verbose=10)
# rfc1= rfc(n_estimators=200, oob_score=True, n_jobs=5, verbose=10)
# rfc1= rfc(n_estimators=2000, oob_score=True, n_jobs=10, criterion='entropy', max_features=.2, verbose=5)

rfc1.fit(dat1.iloc[1:, 1:], dat1.iloc[1:, 0]) # can also works with np array

f= open('oob_score.txt', 'a')
f.write("\t".join([str(rfc1.oob_score_), fname])+ "\n")
f.close()



